package com.dd.machine.main.commons;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.SnapHelper;
import android.util.Log;

/**
 * Created by Administrator on 2017/7/13.
 * sp存储方法类
 */

public class SPUtils {
    //存储二维码
    public static String getQRCode(Context context) {
        String value = context.getSharedPreferences(Constants.SP_QRCODE, Context.MODE_PRIVATE)
                .getString(Constants.QRCODE, null);
        Log.e("QRCode", "" + value);
        return value;
    }
    public static void setQRCode(Context context, String code) {
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_QRCODE, Context.MODE_PRIVATE);
        SharedPreferences.Editor QRCode = sp.edit();
        QRCode.putString(Constants.QRCODE, code);
        QRCode.commit();
        return;
    }

    //判断是不是第一次打开
    public static boolean firstOpen(Context context){
        SharedPreferences setting = context.getSharedPreferences(Constants.SP_OPEN, 0);
        Boolean splash = setting.getBoolean(Constants.OPEN, true);
        return splash;
    }

    public static void setFristOpen(Context context,boolean ret){
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_OPEN, 0);
        SharedPreferences.Editor editor_splash = sp.edit();
        editor_splash.putBoolean(Constants.OPEN, ret);
        editor_splash.commit();
    }

    //判断是不是可以接收极光推送
    public static boolean canReceiver(Context context){
        SharedPreferences setting = context.getSharedPreferences(Constants.SP_RECEIVER, 0);
        Boolean splash = setting.getBoolean(Constants.RECEIVER, false);
        return splash;
    }

    public static void setReceiver(Context context,boolean ret){
        SharedPreferences sp = context.getSharedPreferences(Constants.SP_RECEIVER, 0);
        SharedPreferences.Editor editor_splash = sp.edit();
        editor_splash.putBoolean(Constants.RECEIVER, ret);
        editor_splash.commit();
    }
}
